#include "stdafx.h"

#include "CXTimeline.h"
#include "CXComp.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


CXTimeline::CXTimeline(CXComp & c) : 
	m_Foreground(* this, "Foreground"),
	m_Mask(* this),
	m_Background(* this, "Background")
{
	m_Mask.SetCaption("Mask");

	Attach(&m_Foreground);
	m_Foreground.Append(&m_Mask);
	Attach(&m_Mask);
	Attach(&m_Background);

	SetSequence(&c);
}

CXTimeline::~CXTimeline()
{
	Detach(&m_Foreground);
	Detach(&m_Mask);
	Detach(&m_Background);
}

void CXTimeline::SetSequence(CXComp * pComp)
{
	My::Timeline::SetSequence(pComp);
	if (pComp != 0) {
		m_Mask.SetSegments(&pComp->GetSegments());
		m_Background.SetLayer(&pComp->GetBackground());
	} else {
		m_Mask.SetSegments(0);
		m_Background.SetLayer(0);
	}
}

void CXTimeline::OnOpen()
{
	Xline::OnOpen();
	GetGrid().Append(&m_Foreground);
	GetGrid().Append(&m_Background);
	m_Foreground.Expand();
	m_Mask.Expand();
}

void CXTimeline::OnClose()
{
	m_Mask.Collapse();
	m_Foreground.Collapse();
	GetGrid().Clear();
	Xline::OnClose();
}
